package XYC;

import static org.junit.Assert.assertTrue;
import XYC.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that YichiSpecialBot fires correctly.
 * @author Yichi Xu
 *
 */
public class TestYichiSpecialBotFiring extends RobotTestBed {
  /** Check that if the robot fires a bullet.*/
  private boolean isFired = false;
  private double lastTurnEnergy = -1;
  /**
   * Specifies that SittingDuck and YichiSpecialBot are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,XYC.YichiSpecialBot";
  }
  
  /**
   * This test runs for 5 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 5;
  }
  
  /**
   * After each turn, check to see that we earn some energy by 
   * hitting an enemy.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot YichiSpecialBot = event.getTurnSnapshot().getRobots()[1];
    
    if (lastTurnEnergy < 0) {
      lastTurnEnergy = YichiSpecialBot.getEnergy();
    }
    else {
      if (lastTurnEnergy > YichiSpecialBot.getEnergy()) {
        isFired = true;
      }
      else {
        lastTurnEnergy = YichiSpecialBot.getEnergy();
      }
    }
  }
  
  /**
   * The actual test, which asserts that YichiSpecialBot 
   * fired a bullet during the battle and hit sittingduck.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Check to make sure YichiSpecialBot fired a bullet and hit sittingduck.
    assertTrue("Check YichiSpecialBot fired a bullet and hit sittingduck", isFired);
  }
}
